package cn.csdj.sism.service.impl;

import cn.csdj.sism.dao.EmployeeMapper;
import cn.csdj.sism.pojo.Accommodation;
import cn.csdj.sism.pojo.Class;
import cn.csdj.sism.pojo.Employee;
import cn.csdj.sism.service.EmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
/**
 * EmployeeServiceImpl接口实现类
 * @author 谭世豪
 * 2023/4/10
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public int insert(Employee employee) {
        return employeeMapper.insert(employee);
    }

    @Override
    public int deleteById(Integer id) {
        return employeeMapper.deleteById(id);
    }

    @Override
    public List<Employee> selectAll() {
        return employeeMapper.selectList(null);
    }

    @Override
    public Employee selectById(Integer id) {
        return employeeMapper.selectById(id);
    }

    @Override
    public int update(Employee employee) {
        return employeeMapper.updateById(employee);
    }

    @Override
    public IPage<Employee> selectPages(Integer current, Integer PageSize) {
        IPage<Employee> page=new Page(current,PageSize);
        employeeMapper.selectPage(page,null);
        return page;
    }

    @Override
    public IPage<Employee> selectPagesByChaXun(HashMap chaxun) {
        IPage<Employee> page=new Page<>((Integer) chaxun.get("current"),(Integer) chaxun.get("pageSize"));
        LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(chaxun.get("empName"))){
            lqw.like(Employee::getEmpName,chaxun.get("empName"));
        }
        if (!StringUtils.isEmpty(chaxun.get("educationBackground"))){
            lqw.eq(Employee::getEducationBackground,chaxun.get("educationBackground"));
        }
        if (!StringUtils.isEmpty(chaxun.get("empStatus"))){
            lqw.eq(Employee::getEmpStatus,chaxun.get("empStatus"));
        }
        employeeMapper.selectPage(page,lqw);
        return page;
    }
}
